package SI::Company::BaseInfo;

use base qw/MyDB::Object/;

__PACKAGE__->meta->setup(
    table => 'ComInfo',
    columns =>
    [
        id => { type => 'varchar', length => 5, not_null => 1 },
        name => { type => 'varchar', length => 60, not_null => 1 },
        code => { type => 'varchar', length => 16, not_null => 1 },
        group => { type => 'varchar', length => 40, },
    ],
    allow_inline_column_values => 1,
    primary_key_columns => [ 'id' ],
);

sub init_tab {
    my $self = shift;
    my $stmt = 'CREATE TABLE IF NOT EXISTS ComInfo (
               id VARCHAR(5) PRIMARY KEY NOT NULL, /* 单位编码 */
               name VARCHAR(60) NOT NULL,          /* 单位名称 */
               code VARCHAR(16) NOT NULL,          /* 单位代码 */
               type VARCHAR(40) NOT NULL           /* 单位类型 */
               );';
    my $db = $self->init_db;
    my $dbh = $db->dbh or die $db->error;
    $db->do_transaction(sub {$dbh->do($stmt)})
        or die $db->error;
    return 1;
}


1;
